package com.vrsys.controller;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.LocaleResolver;

import com.vrsys.util.HttpLanguageUtil;

public abstract class BaseController {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    protected LocaleResolver localeResolver;

    @ModelAttribute("lang")
    protected String languageDetecting(HttpServletRequest request) {
        return HttpLanguageUtil.parseLocaleString(request.getHeader("accept-language"));
//        return HttpLanguageUtil.LANG;
    }

    @ModelAttribute("locale")
    protected Locale resolveLocale(HttpServletRequest request) {
        return localeResolver.resolveLocale(request);
    }
}
